package com.noah2021;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 〈〉
 *
 * @author Noah2021
 * @create 2021/3/5
 * @return
 *
 * 测试
 * 不加载 DispatcherServlet
 * http://localhost:8080/simpleframework/hello
 */
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    //注入servlet容器后只执行一次
    @Override
    public void init() throws ServletException {
        System.out.println("init...");
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("执行service方法后再执行doGet方法");
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = "我的简易框架";
//        log.debug("name is" + name);
        req.setAttribute("name", name);
        req.getRequestDispatcher("/WEB-INF/jsp/hello.jsp").forward(req,resp);
    }
    //同样只执行一次
    @Override
    public void destroy() {
        System.out.println("destroy...");
    }
}